package com.ylb.rent.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ylb.rent.config.PageConfig;
import com.ylb.rent.entity.Feetype;
import com.ylb.rent.util.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;

import com.ruoyi.common.enums.BusinessType;
import  com.ylb.rent.entity.Country;
import com.ylb.rent.service.ICountryService;



/**
 * 国家Controller
 * 
 * @author ylb
 * @date 2023-06-29
 */
@RestController
@RequestMapping("/country/country")
public class CountryController
{
    @Autowired
    private ICountryService countryService;

    /**
     * 查询国家列表
     */
    @PreAuthorize("@ss.hasPermi('country:country:list')")
    @GetMapping("/list")
    public String list(Country country, PageConfig pageConfig)
    {
        PageHelper.startPage(pageConfig);

        List<Country> list = countryService.selectCountryList(country);
        return R.successJSONData(new PageInfo<>(list));


    }


    /**
     * 获取国家详细信息
     */
    @PreAuthorize("@ss.hasPermi('country:country:query')")
    @GetMapping(value = "/{id}")
    public String getInfo(@PathVariable("id") Long id)
    {
        return R.successJSONData(countryService.selectCountryById(id));
    }

    /**
     * 新增国家
     */
    @PreAuthorize("@ss.hasPermi('country:country:add')")
    @Log(title = "国家", businessType = BusinessType.INSERT)
    @PostMapping
    public String add(@RequestBody Country country)
    {
        return R.successJSONData(countryService.insertCountry(country));
    }

    /**
     * 修改国家
     */
    @PreAuthorize("@ss.hasPermi('country:country:edit')")
    @Log(title = "国家", businessType = BusinessType.UPDATE)
    @PutMapping
    public String edit(@RequestBody Country country)
    {
        return R.successJSONData(countryService.updateCountry(country));
    }

    /**
     * 删除国家
     */
    @PreAuthorize("@ss.hasPermi('country:country:remove')")
    @Log(title = "国家", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public String remove(@PathVariable Long[] ids)
    {
        return R.successJSONData(countryService.deleteCountryByIds(ids));
    }
}
